<template>
  <div id="data-view-index">
    <dv-loading v-if="loading">Loading...</dv-loading>
    <dv-full-screen-container v-else>
      <div class="main-header">
        <div class="mh-left" @click="routerUrl('datav-policy')">
          <a>政策速递</a>
          <dv-decoration-8 style="width:200px;height:50px;" />
        </div>
        <div class="mh-middle" @click="changeClassName()">
          {{ commonData.system_name }} <br><a :class="className" href="javascript:;" @click="routerUrl('index-index')">返回控制台</a>
        </div>
        <div class="mh-right" @click="routerUrl('datav-project')">
          <a>项目介绍</a>
          <dv-decoration-8 :reverse="true" style="width:200px;height:50px;" />
        </div>
      </div>

      <dv-border-box-8 class="main-container-datav">
        <dv-border-box-3 class="left-chart-container">
          <Left-Chart-1 :devices-data="commonData.devices" />
          <Left-Chart-3 :devices-data="commonData.devices" />
        </dv-border-box-3>

        <div class="right-main-container">
          <div class="rmc-top-container">
            <dv-border-box-3 class="rmctc-left-container">
              <Center-Cmp />
            </dv-border-box-3>
            <div class="rmctc-right-container">
              <dv-border-box-13 class="rmctc-chart-2" :reverse="true">
                <Right-Chart-2 :video-monitors="commonData.video_monitors" />
              </dv-border-box-13>
            </div>
          </div>
          <dv-border-box-4 class="rmc-bottom-container">
            <Bottom-Charts :devices="devices" />
          </dv-border-box-4>
        </div>
      </dv-border-box-8>
    </dv-full-screen-container>
  </div>
</template>

<script>
import { getAll, getStates } from '@/api/datav'
import LeftChart1 from './components/LeftChart1'
import LeftChart3 from './components/LeftChart3'
import CenterCmp from './components/CenterCmp'
import RightChart2 from './components/RightChart2'
import BottomCharts from './components/BottomCharts'
import { mapGetters } from 'vuex'
export default {
  name: 'DataView',
  components: {
    LeftChart1,
    LeftChart3,
    CenterCmp,
    RightChart2,
    BottomCharts
  },
  data() {
    return {
      loading: true,
      commonData: {},
      devices: [],
      videoMonitors: [],
      isFullscreen: false,
      className: 'hid'
    }
  },
  computed: {
    ...mapGetters(['project'])
  },
  created() {
    this.getAll()
    setInterval(() => {
      this.getStates()
    }, 30000)
  },
  methods: {
    async getAll() {
      const { data } = await getAll({ project_id: this.project.id })
      this.commonData = data
      this.setData(data)
      this.loading = false
    },
    async getStates() {
      const { data } = await getStates({ project_id: this.project.id })
      this.setData(data)
    },
    setData(data) {
      this.devices = data.devices_states
    },
    routerUrl(name) {
      this.$router.push({ name: name })
    },
    changeClassName() {
      this.className = this.className ? '' : 'hid'
    }
  }
}
</script>
<style lang="scss">
#data-view-index {
  width: 100%;
  height: 100%;
  background-color: #030409;
  color: #fff;

  #dv-full-screen-container {
    background-image: url('https://api.zesi.com.cn/storage/datav/bg-dashboard.png');
    background-size: 100% 100%;
    box-shadow: 0 0 3px blue;
    display: flex;
    flex-direction: column;
  }

  .main-header {
    height: 100px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom:24px;
    .mh-left, .mh-right {
      display:flex;
      flex-direction: column;
      cursor:pointer;
      a{
        font-size: 18px;
        color: rgb(145, 208, 233);
        text-decoration: none;
        margin:48px 0 -12px 0;
      }
    }
    .mh-left{
      text-align:right;
      padding-left:32px;
      a{
        padding-right:16px;
      }
    }
    .mh-right{
      text-align:left;
      padding-right:32px;
      a{
        padding-left:16px;
      }
    }

    .mh-middle {
      font-size: 30px;
      padding:24px 12px 0 12px;
      text-align:center;
      a{
        display:inline-block;
        font-size:16px;
        text-decoration: underline;
        color:#eee;
        &.hid{
          display:none;
        }
      }
    }
  }
  .main-container-datav {
    height: calc(100% - 80px);
    .border-box-content {
      padding: 20px;
      box-sizing: border-box;
      display: flex;
    }
  }
  .left-chart-container {
    width: 22%;
    padding: 10px;
    box-sizing: border-box;

    .border-box-content {
      flex-direction: column;
    }
  }

  .right-main-container {
    width: 78%;
    padding-left: 5px;
    box-sizing: border-box;
  }

  .rmc-top-container {
    height: 60%;
    display: flex;
  }

  .rmctc-left-container {
    width: 60%;
  }

  .rmctc-right-container {
    width: 40%;
  }

  .rmc-bottom-container {
    height: 40%;
  }

  .rmctc-chart-1, .rmctc-chart-2 {
    height: 100%;
  }
}
</style>
